package exodia;
/**
 * ModGames (C) 2007 Pedro Miller Rabinovitch.
 * 
 * Permission is hereby granted to copy and use this material for any free or educational purpose.
 * Please do not use this for commercial purposes before letting me know (but it'll be fine).
 * 
 * Contact me via gmail, account pedromr
 * http://exodia.org
 * 
 * $Id: StripDefinition.java 41 2007-12-04 00:57:21Z pedromr $
 */
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


/**
 * @author Miller
 * Defines an animation strip
 */
public class StripDefinition {
	private static final int GRAPHICS_TOP_LEFT = Graphics.TOP | Graphics.LEFT;
	
	protected Image image;
	protected int frameWidth, frameHeight;
	private int cols;
	private int rows;
	
	public StripDefinition( Image image, int frameWidth, int frameHeight ) {
		this.image = image;
		this.frameHeight = frameHeight;
		this.frameWidth = frameWidth;
		this.rows = image.getHeight()/frameHeight;
		this.cols = image.getWidth()/frameWidth;
	}
	
	public StripDefinition( Image image, int numberOfFrames ) {
		this.image = image;
		this.frameHeight = image.getHeight();
		this.frameWidth = image.getWidth()/numberOfFrames;
		this.rows = 1;
		this.cols = numberOfFrames;
	}
	
	public void drawFrame(Graphics g, int x, int y, int currFrame, int transform) {
		
		int x0 = ( currFrame * frameWidth ) % image.getWidth();
		int y0 = ( currFrame / ( image.getWidth() / frameWidth )) * image.getHeight();		
				
		g.drawRegion( image, x0, y0, frameWidth, frameHeight, transform, x, y, GRAPHICS_TOP_LEFT);		
	}

	public int getNumberOfFrames() {
		return rows * cols;
	}
	
}
